package com.lichuang.dedao.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lichuang.dedao.user.entity.Follow;
import com.lichuang.dedao.user.enums.FollowStatus;
import com.lichuang.dedao.user.mapper.FollowMapper;
import com.lichuang.dedao.user.service.IFollowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 关注 服务实现类
 * </p>
 *
 * @author hanghang
 * @since 2019-07-13
 */
@Service
public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow> implements IFollowService {

    @Override
    public List<Follow> selectFollowedByUserId(Integer userId) {
        Follow followParam = new Follow();
        followParam.setUserId(userId)
                .setStatus(FollowStatus.FOLLOWED.getValue());
        QueryWrapper queryWrapper = new QueryWrapper(followParam);
        List<Follow> follows = baseMapper.selectList(queryWrapper);
        return follows;
    }

    @Override
    public List<Follow> selectFollowerByUserId(Integer userId) {
        Follow followParam = new Follow();
        followParam.setFollowedUserId(userId)
                .setStatus(FollowStatus.FOLLOWED.getValue());
        QueryWrapper queryWrapper = new QueryWrapper(followParam);
        List<Follow> follows = baseMapper.selectList(queryWrapper);
        return follows;
    }

    @Override
    public Integer follow(Integer userId, Integer followedUserId) {
        Follow follow = new Follow();
        follow.setUserId(userId)
                .setFollowedUserId(followedUserId)
                .setStatus(FollowStatus.FOLLOWED.getValue())
                .setCreateTime(LocalDateTime.now());
        Integer result = baseMapper.insert(follow);
        return result;
    }
}
